applicationRoutes.js ➔ ... ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 2 Features 2
Metric Value
cc 1
c 2
b 2
f 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 9.4285
1 4
import App from "app";
2
3
const Pages = App.components.pages;
4
const Router = App.service("ROUTER");
5
6
Router.setDefaultLayout(App.components.Application);
7
Router.setDefaultTitle("Star");
8
9
Router.addRoute("/", Pages.Home);
10
Router.addRoute("/foo", Pages.Foo);
11
Router.addRoute("/movies", Pages.Movies);
12
Router.addRoute("/:type/:mediaToDisplay", Pages.Detail);
13
14
Router.addResolver("mediaToDisplay", (value, context, next) => {
15
    const hash = {
16
        tv: "tv",
17
        movie: "movie",
18
        person: "person"
19
    };
20
21 2
    if (!hash.hasOwnProperty(context.params.type)) {
22
        Router.setRoute("/not-found"); // @todo improve
23
        return;
24
    }
25
26
    App.provider("Movies").get(hash[context.params.type], value)
27
        .then(media => {
28
            context.params.media = media;
29
            context.params.media.media_type = context.params.type;
30
            next();
31
        })
32
        .catch(err => {
0 ignored issues
show
Unused Code introduced by
The parameter err is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
33
            Router.setRoute("/not-found"); // @todo improve
34
        });
35
});
36
37
/******************************************************************************/
38
/* Examples *******************************************************************/
39
/******************************************************************************/
40
41
// Given an url argument named :userId will fetch user data from API and
42
// add to context
43
// Router.addResolver("userId", (value, context, next) => {
44
//     // you can render an loading animation, if you want
45
//     App.providers("user").find(value).then(user => {
46
//         context.user = user;
47
//         next();
48
//     });
49
// });
50
51
// // Add a route that don't render a component
52
// Router.addRoute("/another-route", {
53
//     handler: (context) => console.log("do stuff"),
54
// });
55
56
57
/******************************************************************************/
58
/* Not found ******************************************************************/
59
/******************************************************************************/
60
Router.addRoute("*", {
61
    component: App.components.NotFound,
62
    title: "Ops!"
63
});
64